#include "wtire_thread.h"

wtire_thread::wtire_thread(QWaitCondition &cond,QReadWriteLock &lock,QString &m,QObject *parent) :QThread(parent),msg(m),rwlock(lock),cond(cond)
{

    flag = false;
    this->loop = 0;
}

void wtire_thread:: stop(){
    mutex.lock();
    flag = true;
    mutex.unlock();
}
void wtire_thread::run(){
    //每隔1s写当前loop的值
    forever{
        mutex.lock();
        if(flag){
            flag = false;

            mutex.unlock();
            cond.wakeAll();//唤醒所有等条件变量的线程结束
            break;
        }
        mutex.unlock();
        //QThread ::sleep(1);
        rwlock.lockForWrite();
        msg = "Current loop is"+ QString::number(this->loop++);

        rwlock.unlock();
        cond.wakeAll();//唤醒所有等条件变量的线程结束
//        QThread:: sleep(1);

    }
    return;
}
